package com.woan.api.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class CommonUtil {
	/**
	 * 获取五位随机数
	 * @return
	 */
    public static String Random(){
    	String result="";
    	for(int i=0;i<5;i++){
    		int random=(int)(Math.random()*10);
    		result=result+random;
    	}
    	return result;
    }
    /**
     *  获取随机字符
     * @param length
     * @return
     */
	public static String RandomString(int length) {
	     String[] arrs=new String[]{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
	     StringBuffer sub=new StringBuffer("");
	     for(int i=0;i<length;i++){
	    	 int random=(int)(Math.random()*26);
	    	 sub.append(arrs[random]);
	     }
		 return sub.toString();
	}
	/**
     *  获取随机数字
     * @param length
     * @return
     */
	public static String RandomNumber(int length) {
	     StringBuffer sub=new StringBuffer("");
	     for(int i=0;i<length;i++){
	    	 int random=(int)(Math.random()*10);
	    	 sub.append(random);
	     }
		 return sub.toString();
	}
	 /**
     *  获取随机字符
     * @param length
     * @return
     */
	public static String RandomStrNum(int length) {
	     String[] arrs=new String[]{"A","0","B","1","C","2","D","3","E","4","F","5","G","6","H","7","I","8","J","9","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
	     StringBuffer sub=new StringBuffer("");
	     for(int i=0;i<length;i++){
	    	 int random=(int)(Math.random()*36);
	    	 sub.append(arrs[random]);
	     }
		 return sub.toString();
	}
	
	
	 /**
     *  获取随机一组颜色字符串
     * @param length
     * @return
     */
	public static String RandomColor(int length) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
	     String[] arrs=new String[]{"A","0","B","1","C","2","D","3","E","4","F","5","6","7","8","9"};
	     StringBuffer sub=new StringBuffer("");
	     sub.append(formatter.format(new Date()));
	     for(int i=0;i<length;i++){
	    	 int random=(int)(Math.random()*16);
	    	 sub.append(arrs[random]);
	     }
		 return sub.toString();
	}
	
	/**
     *  获取随机数字(带日期）
     * @param length
     * @return
     */
	public static String RandomNumberDate(int length) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
		Date curDate = new Date();// 获取当前时间
	     StringBuffer sub=new StringBuffer("");
	     sub.append(formatter.format(curDate));
	     for(int i=0;i<length;i++){
	    	 int random=(int)(Math.random()*10);
	    	 sub.append(random);
	     }
		 return sub.toString();
	}
	
	/**
     *  获取随机字符(带日期HHmmss)
     * @param length
     * @return
     */
	public static String RandomStrNumDate(int length) {
		SimpleDateFormat formatter = new SimpleDateFormat("HHmmss");
		 Date curDate = new Date();// 获取当前时间
		 String[] arrs=new String[]{"0","1","2","3","4","5","6","7","8","9"};
	     StringBuffer sub=new StringBuffer("");
	     for(int i=0;i<length;i++){
	    	 int random=(int)(Math.random()*10);
	    	 sub.append(arrs[random]);
	     }
	     sub.append(formatter.format(curDate));
	     for(int i=0;i<length;i++){
	    	 int random=(int)(Math.random()*10);
	    	 sub.append(arrs[random]);
	     }
	     
		 return sub.toString();
	}
	
	/**
     *  获取随机字符(带日期yyyyMMddHHmmss)
     * @param length
     * @return
     */
	public static String RandomStrNumDateTime(int length) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
		 Date curDate = new Date();// 获取当前时间
		 String[] arrs=new String[]{"0","1","2","3","4","5","6","7","8","9"};
	     StringBuffer sub=new StringBuffer("");
	     sub.append(formatter.format(curDate));
	     for(int i=0;i<length;i++){
	    	 int random=(int)(Math.random()*10);
	    	 sub.append(arrs[random]);
	     }
	     
		 return sub.toString();
	}
}
